package HomeWork4;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class Main {
    public static void printChars(String str, int count) {
//        Map<Character, Integer> charCounts = new HashMap<>();
//        for (int i = 0; i < str.length(); i++) {
//            char c = str.charAt(i);
//            charCounts.put(c, charCounts.getOrDefault(c, 0) + 1);
//        }
//        for (char c : charCounts.keySet()) {
//            if (charCounts.get(c) == count) {
//                System.out.println(c);
//            }
//        }
//    }
        Map<Character, Long> charCounts = str.chars()
                .mapToObj(c -> (char) c)
                .collect(Collectors.groupingBy(c -> c, Collectors.counting()));
        charCounts.entrySet().stream()
                .filter(entry -> entry.getValue() == count)
                .map(Map.Entry::getKey)
                .forEach(System.out::println);
    }
}

